<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>i2c: C:/Users/Jon/Downloads/OOP/db-control/dbMajor.php Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />

<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">i2c
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">C:/Users/Jon/Downloads/OOP/db-control/dbMajor.php</div>  </div>
</div>
<div class="contents">
<a href="db_major_8php.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?php
<a name="l00002"></a>00002 
<a name="l00026"></a><a class="code" href="classdb_major.html">00026</a> <span class="keyword">class </span><a class="code" href="classdb_major.html">dbMajor</a> {
<a name="l00027"></a>00027 
<a name="l00028"></a>00028     <span class="keyword">private</span> $db;
<a name="l00029"></a>00029 
<a name="l00030"></a><a class="code" href="classdb_major.html#aea6c4d653e217f31256ded5783ed58f4">00030</a>     <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_major.html#aea6c4d653e217f31256ded5783ed58f4">createTable</a>() {
<a name="l00031"></a>00031         <span class="comment">//Create table major</span>
<a name="l00032"></a>00032         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;</span>
<a name="l00033"></a>00033 <span class="stringliteral">            create table major(</span>
<a name="l00034"></a>00034 <span class="stringliteral">                majorName    varchar(45) NOT NULL,</span>
<a name="l00035"></a>00035 <span class="stringliteral">                constraint PK_Major PRIMARY KEY (majorName)</span>
<a name="l00036"></a>00036 <span class="stringliteral">                );</span>
<a name="l00037"></a>00037 <span class="stringliteral">            &quot;</span>;
<a name="l00038"></a>00038         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00039"></a>00039         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00040"></a>00040         mysql_close();
<a name="l00041"></a>00041         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00042"></a>00042             echo mysql_error();
<a name="l00043"></a>00043             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00044"></a>00044         } <span class="keywordflow">else</span> {
<a name="l00045"></a>00045             <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00046"></a>00046             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;Biology&#39;)&quot;</span>);
<a name="l00047"></a>00047             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;CA&#39;)&quot;</span>);
<a name="l00048"></a>00048             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;CIS&#39;)&quot;</span>);
<a name="l00049"></a>00049             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;English&#39;)&quot;</span>);
<a name="l00050"></a>00050             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;Hisotry&#39;)&quot;</span>);
<a name="l00051"></a>00051             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;PS&#39;)&quot;</span>);
<a name="l00052"></a>00052             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;Psyc&#39;)&quot;</span>);
<a name="l00053"></a>00053             mysql_query(<span class="stringliteral">&quot;INSERT INTO major VALUES(&#39;Unknown&#39;)&quot;</span>);
<a name="l00054"></a>00054             mysql_close();
<a name="l00055"></a>00055         }
<a name="l00056"></a>00056 
<a name="l00057"></a>00057         <span class="comment">//Previous query was successful.</span>
<a name="l00058"></a>00058         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00059"></a>00059     }
<a name="l00060"></a>00060 
<a name="l00065"></a><a class="code" href="classdb_major.html#a30cf5cb3cdda51535a642fad19ef4352">00065</a>     <span class="keyword">function</span> <a class="code" href="classdb_major.html#a30cf5cb3cdda51535a642fad19ef4352">getAllMajors</a>() {
<a name="l00066"></a>00066         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = <span class="stringliteral">&quot;SELECT * FROM major&quot;</span>;
<a name="l00067"></a>00067         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>( );
<a name="l00068"></a>00068         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00069"></a>00069         mysql_close();
<a name="l00070"></a>00070         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00071"></a>00071             echo mysql_error( );
<a name="l00072"></a>00072             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00073"></a>00073         }
<a name="l00074"></a>00074 
<a name="l00075"></a>00075         <span class="comment">//Query was successful.</span>
<a name="l00076"></a>00076         <span class="keywordflow">return</span> <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>;
<a name="l00077"></a>00077     }
<a name="l00078"></a>00078 
<a name="l00084"></a><a class="code" href="classdb_major.html#a778dd2d17ac654a06021a4bb761add65">00084</a>     <span class="keyword">static</span> <span class="keyword">function</span> <a class="code" href="classdb_major.html#a778dd2d17ac654a06021a4bb761add65">addMajor</a>($m, &amp;$id) {
<a name="l00085"></a>00085         <span class="keywordflow">if</span> (!$m instanceof major) {
<a name="l00086"></a>00086             echo (<span class="stringliteral">&quot;Invalid arguement insertInto ( ) function&lt;br /&gt;&quot;</span>);
<a name="l00087"></a>00087             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00088"></a>00088         }
<a name="l00089"></a>00089         <span class="comment">//Compose the INSERT INTO query srting. Primary key value is missing.</span>
<a name="l00090"></a>00090         <span class="comment">//Database server automatically generates a unique ID for the primary</span>
<a name="l00091"></a>00091         <span class="comment">//key.</span>
<a name="l00092"></a>00092         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;INSERT INTO major VALUES (&#39;%s&#39;)&quot;</span>,
<a name="l00093"></a>00093                         $m-&gt;getName()
<a name="l00094"></a>00094         );
<a name="l00095"></a>00095         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>( );
<a name="l00096"></a>00096         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00097"></a>00097         mysql_close( );
<a name="l00098"></a>00098         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00099"></a>00099             echo mysql_error ( );
<a name="l00100"></a>00100             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00101"></a>00101         }
<a name="l00102"></a>00102         <span class="comment">//query was successful.</span>
<a name="l00103"></a>00103         printf(<span class="stringliteral">&quot;Major added has id %d\n&lt;br /&gt;&quot;</span>, mysql_insert_id());
<a name="l00104"></a>00104         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00105"></a>00105     }
<a name="l00106"></a>00106 
<a name="l00112"></a><a class="code" href="classdb_major.html#a2855f7001f9c2c2ed6ce06ddf4225c57">00112</a>     <span class="keyword">function</span> <a class="code" href="classdb_major.html#a2855f7001f9c2c2ed6ce06ddf4225c57">checkName</a>($m) {
<a name="l00113"></a>00113         <span class="keywordflow">if</span> (!($m instanceof <a class="code" href="class_major.html">Major</a>)) {
<a name="l00114"></a>00114             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00115"></a>00115         }
<a name="l00116"></a>00116         $majorName = $m-&gt;getName();
<a name="l00117"></a>00117         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>();
<a name="l00118"></a>00118         <span class="keywordflow">if</span> (mysql_num_rows(mysql_query(<span class="stringliteral">&quot;SELECT * FROM major WHERE majorName=</span>
<a name="l00119"></a>00119 <span class="stringliteral">                $majorName&quot;</span>))
<a name="l00120"></a>00120                 == <span class="keyword">false</span>) {
<a name="l00121"></a>00121             mysql_close();
<a name="l00122"></a>00122             <span class="comment">//nothing existsmysql_num_rows</span>
<a name="l00123"></a>00123             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00124"></a>00124         } <span class="keywordflow">else</span> {
<a name="l00125"></a>00125             <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00126"></a>00126         }
<a name="l00127"></a>00127     }
<a name="l00128"></a>00128 
<a name="l00134"></a><a class="code" href="classdb_major.html#a89573bcce91819694282ed35ab966c5c">00134</a>     <span class="keyword">function</span> <a class="code" href="classdb_major.html#a89573bcce91819694282ed35ab966c5c">getMajor</a>($majorName) {
<a name="l00135"></a>00135         $m = <span class="keyword">new</span> <a class="code" href="class_major.html">Major</a> ();
<a name="l00136"></a>00136         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<span class="stringliteral">&quot;SELECT * FROM major WHERE majorName=$majorName&quot;</span>);
<a name="l00137"></a>00137         <span class="keywordflow">if</span> (!<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>) {
<a name="l00138"></a>00138             <span class="keywordflow">return</span> <span class="keyword">false</span>; <span class="comment">//name does not exist</span>
<a name="l00139"></a>00139         } <span class="keywordflow">else</span> {
<a name="l00140"></a>00140             $row = mysql_fetch_assoc(<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a>);
<a name="l00141"></a>00141             $m-&gt;setName($majorName);
<a name="l00142"></a>00142             <span class="keywordflow">return</span> $m;
<a name="l00143"></a>00143         }
<a name="l00144"></a>00144     }
<a name="l00145"></a>00145 
<a name="l00151"></a><a class="code" href="classdb_major.html#a721775523535ed0810e9642a5c6a8903">00151</a>     <span class="keyword">function</span> <a class="code" href="classdb_major.html#a721775523535ed0810e9642a5c6a8903">deleteMajor</a>($m) {
<a name="l00152"></a>00152         <span class="keywordflow">if</span> (!$m instanceof <a class="code" href="class_major.html">Major</a>) {
<a name="l00153"></a>00153             echo (<span class="stringliteral">&quot;Invalid argument deleteFrom( ) function&lt;br /&gt;&quot;</span>);
<a name="l00154"></a>00154             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00155"></a>00155         }
<a name="l00156"></a>00156 
<a name="l00157"></a>00157         <span class="comment">//Compose the DELETE FROM query string.</span>
<a name="l00158"></a>00158         <a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a> = sprintf(<span class="stringliteral">&quot;DELETE FROM major WHERE majorName = &#39;%s&#39;&quot;</span>,
<a name="l00159"></a>00159                         $m-&gt;getName()
<a name="l00160"></a>00160         );
<a name="l00161"></a>00161         <a class="code" href="db-control_2inc_2functions_8php.html#aca07cf60afd49a5a5b583459f5423045">connectToDatabase</a>( );
<a name="l00162"></a>00162         <a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> = mysql_query(<a class="code" href="internship__list__dateadded_8php.html#af59a5f7cd609e592c41dc3643efd3c98">$query</a>);
<a name="l00163"></a>00163         mysql_close( );
<a name="l00164"></a>00164         <span class="keywordflow">if</span> (<a class="code" href="admin_2internship__list_8php.html#a112ef069ddc0454086e3d1e6d8d55d07">$result</a> == <span class="keyword">false</span>) {
<a name="l00165"></a>00165             echo mysql_error( );
<a name="l00166"></a>00166             <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00167"></a>00167         }
<a name="l00168"></a>00168 
<a name="l00169"></a>00169         <span class="comment">//Query was successful.</span>
<a name="l00170"></a>00170         <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00171"></a>00171     }
<a name="l00172"></a>00172 
<a name="l00173"></a>00173 
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175 
<a name="l00176"></a>00176 ?&gt;
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>



<hr class="footer"/><address class="footer"><small>
Generated on Tue Nov 29 2011 18:18:54 for i2c by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.7.5.1
</small></address>

</body>
</html>
